Skip to content

fix(auth): surface .sentryclirc source in self-hosted login errors#976

Merged
betegon merged 12 commits into
mainfrom
fix/sentryclirc-login-ux
May 19, 2026
Merged

fix(auth): surface .sentryclirc source in self-hosted login errors#976
betegon merged 12 commits into
mainfrom
fix/sentryclirc-login-ux

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented May 18, 2026

When sentry auth login rejects a self-hosted URL that came from .sentryclirc, the old error just said --url was not provided — which doesn't tell you why it was blocked or where the URL came from. Now it names the exact file and gives you the fix in one line:

Refusing to log in against https://sentry.example.com — this URL was read from
.sentryclirc (/Users/you/.sentryclirc) but hasn't been confirmed as trusted yet.

To authenticate against this self-hosted instance, confirm the host explicitly:
  sentry auth login --url https://sentry.example.com

The rc context logic is extracted into small helpers (resolveRcContext, maybeWarnRcToken) to keep func's cyclomatic complexity in check.

Relates to #975.

When auth login rejects a non-SaaS URL that arrived via the .sentryclirc
shim, the error now names the file that provided the URL and gives the
exact command to fix it, rather than a generic "--url was not provided"
message.

Also shows a one-line tip when the user runs auth login without --token
but .sentryclirc already has a token — pointing them at the faster token
path instead of silently starting the OAuth device flow.

Closes #975
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-976/

Built to branch gh-pages at 2026-05-18 20:29 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

Codecov Results 📊

6980 passed | Total: 6980 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +5
Passed Tests 📈 +5
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 81.16%. Project has 14092 uncovered lines.
✅ Project coverage is 77.15%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/commands/auth/login.ts 81.16% ⚠️ 13 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    77.14%    77.15%    +0.01%
==========================================
  Files          320       320         —
  Lines        61615     61664       +49
  Branches         0         0         —
==========================================
+ Hits         47530     47572       +42
- Misses       14085     14092        +7
- Partials         0         0         —

Generated by Codecov Action

Comment thread src/commands/auth/login.ts Outdated
@betegon betegon marked this pull request as ready for review May 18, 2026 16:19
betegon and others added 5 commits May 18, 2026 18:20
Partial tokens in error messages and log output can end up in CI logs,
terminal recordings, and bug reports. Use placeholder strings instead.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
log.info fires before the OAuth flow starts — wrong timing and wrong
visual weight. Return the tip as a hint instead so it appears as a
muted footer after login completes, consistent with how every other
command surfaces follow-up suggestions.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…nType>

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/commands/auth/login.ts Outdated
urlFromRc is undefined when --url is passed explicitly, so gating on it
silently dropped --url from the hint, pointing users at SaaS. Gate on
!isSaaSTrustOrigin(effectiveHost) instead so the hint is always correct
regardless of how the host was supplied.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/commands/auth/login.ts
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 52c14dd. Configure here.

Comment thread src/commands/auth/login.ts Outdated
If .sentryclirc has a URL that doesn't match effectiveHost the stored
token belongs to a different instance. Showing the hint would suggest
using it for the wrong host, which would always fail with an auth error.
No API call needed — the host mismatch is detectable from rcConfig.url.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/commands/auth/login.ts
betegon and others added 4 commits May 18, 2026 22:14
Two fixes:
- resolveRcContext now uses this.cwd (injected via SentryContext) instead
  of process.cwd(), making rc-related login behavior testable
- rcTokenHint now suppresses the hint when .sentryclirc has no URL and
  effectiveHost is self-hosted — a bare token in rc is almost certainly
  a SaaS token and pairing it with a self-hosted --url would always fail

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Covers the five branches that were implicated in review bugs:
no token, SaaS match, self-hosted rc URL match, rc URL mismatch,
and bare SaaS token against a self-hosted host.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Static imports are hoisted and evaluate before mock.module() runs,
so login.ts would bind the real consola logger instead of fakeLog —
breaking the interactive prompt tests. Pull rcTokenHint into the
existing dynamic import block that was already there for this reason.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@betegon betegon merged commit e630bf9 into main May 19, 2026
30 checks passed
@betegon betegon deleted the fix/sentryclirc-login-ux branch May 19, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant